import { INCREMENT, DECREMENT } from '../constant'


// 当传递过来的'上一个状态' 为空或者undefined 时 将他初始化一个数值返回
const initState = 0
export default function countReducer(prevState = initState, action) {
  const { type, data } = action
  switch (type) {
    case INCREMENT:
      return prevState + data;
    case DECREMENT:
      return prevState - data
    default:
      return prevState
  }
}